<?php
if (!defined('IN_IA')) {
    exit('Access Denied');
}
$openid = get_sysopenid(true);

$memberinfo = get_member_info($openid);

if (checksubmit("submit")) {
	$params    = array(
		'id' => 0,
        'uid' => $memberinfo['id'],
        'type' => 0,
        'content' => $_GPC['data']['content']
    );
    pdo_insert('eshop_member_message',$params);
    
    $condition = " and uid=" . intval($memberinfo['id']);
    $params    = array(
		'timestamp' => date("Y-m-d H:i:s"),
    );
    $sql = "select * from " . tablename('eshop_member_message_queue') . " where 1 {$condition}";
    $list = pdo_fetchall($sql);
    if(empty($list)){
    	$params    = array(
	        'uid' => $memberinfo['id'],
	        'new_up_num' => 1,
	        'new_down_num' => 0
	    );
	    pdo_insert('eshop_member_message_queue',$params);
    }
    else{
    	$sql = "update " . tablename('eshop_member_message_queue') . " set new_up_num = new_up_num + 1,timestamp=:timestamp where 1 {$condition}";
    	pdo_query($sql,$params);
    }
    
    message("回复成功！", create_url('mobile',array('do'=>'news','act'=>'shopwap')), 'success'); 
}
else{
	$params = array(
			':id' => $memberinfo["id"],
			);
	$sql = "select * from " . tablename('eshop_member_message') . " where uid=:id order by timestamp desc limit 0,50";
	$list = pdo_fetchall($sql, $params);

	$condition = " and uid=" . intval($memberinfo['id']);
    $sql = "update " . tablename('eshop_member_message_queue') . " set new_down_num = 0 where 1 {$condition}";
    pdo_query($sql);

}			
include page('news');